package com.ihisomp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ihisomp.entity.OmpUserRole;
import com.ihisomp.entity.OrgDept;
import com.ihisomp.entity.OrgDeptToFunction;
import com.ihisomp.mapper.OrgDeptToFunctionMapper;
import com.ihisomp.service.IOrgDeptToFunctionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 科室与职能关系 服务实现类
 * </p>
 *
 * @author zy
 * @since 2022-03-22
 */
@Service
public class OrgDeptToFunctionServiceImpl extends ServiceImpl<OrgDeptToFunctionMapper, OrgDeptToFunction> implements IOrgDeptToFunctionService {

    /**
     * 根据科室编码删除科室职能
     *
     * @param deptKey
     * @return
     */
    @Override
    public int deleteByDeptKey(String deptKey) {
        return baseMapper.deleteByDeptKey(deptKey);
    }

    /**
     * 根据科室编码查询科室职能
     *
     * @param deptKey
     * @return
     */
    @Override
    public List<String> getFunctionByDeptKey(String deptKey) {
        QueryWrapper<OrgDeptToFunction> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dept_key", deptKey);
        queryWrapper.orderByAsc("dept_function_key");
        List<OrgDeptToFunction> orgDeptToFunctions = baseMapper.selectList(queryWrapper);
        List<String> list = new ArrayList();
        for (int i = 0; i < orgDeptToFunctions.size(); i++) {
            list.add(orgDeptToFunctions.get(i).getDeptFunctionKey());
        }
        return list;
    }
}
